//
//  StockExchangeJaList.m
//  MarketDataColloctor
//
//  Created by jiro on 10/02/20.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "StockExchangeJaList.h"


@implementation StockExchangeJaList

+ (id) stockExchangeJaListWithPgResult: (PGresult*) res
{
	StockExchangeJaList* ret = [ [ StockExchangeJaList alloc ] init ];

	int row = PQntuples( res );
	int column = PQnfields( res );
	for ( int i = 0; i < row; i++ ) 
	{
		NSMutableArray* values = [ NSMutableArray array ];
		for ( int j = 0; j < column; j++ )
		{
			[ values addObject: [ NSString stringWithFormat: @"%s", PQgetvalue( res, i, j ) ] ];
		}
		StockExchangeJa* exchange = [ StockExchangeJa stockExchangeJaWithDbRespose: values ];
		[ ret addObject: exchange ];
	}
	return ret;
}

- (id) init
{
	self = [ super init ];
	return self;
}
- (NSString*) sqlInsertStatement
{
	NSMutableString* sql = [ NSMutableString string ];
	[ sql appendFormat: @"insert into %@ values\n", kText_StockExchangeJaTable ];
	NSEnumerator* e = [ self objectEnumerator ];
	StockExchangeJa* value;
	
	BOOL firstValue = YES;
	while ( value = [ e nextObject ] )
	{
		if ( firstValue ) {
			firstValue = NO;
		} else {
			[ sql appendString: @", " ];
		}
		[ sql appendFormat: @"%@\n", [ value queryInsertValue ] ];
	}
	[ sql appendString: @";\n" ];	
	return sql;	
}

@end
